package com.hellobike.haxing.web.user;

import com.hellobike.haxing.anno.NoAuth;
import com.hellobike.haxing.request.location.LocationRequest;
import com.hellobike.haxing.request.user.LocationParam;

import com.hellobike.haxing.search.vo.SearchLocationVo;
import com.hellobike.haxing.user.ILocationService;
import com.hellobike.haxing.user.api.LoginApi;
import com.hellobike.haxing.user.vo.CityVo;
import com.hellobike.haxing.user.vo.DistrictVo;
import com.hellobike.haxing.user.vo.ProvinceVo;
import com.hellobike.haxing.user.vo.StreetVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hellobike.haxing.order.result.Result;

import java.util.List;

@Api(tags = "用户定位")
@RequestMapping("/location")
@RestController
@NoAuth
public class LocationController {

    @Autowired
    private ILocationService locationService;

    @Reference
    private LoginApi loginApi;

    @ApiOperation("临时缓存用户定位查询信息")
    @RequestMapping(value = "/save", method = {RequestMethod.POST, RequestMethod.GET})
    public Result<SearchLocationVo> location(@RequestBody LocationParam location) {
        return locationService.saveLocation(location);
    }

    @ApiOperation("展示省信息")
    @RequestMapping(value = "/province", method = RequestMethod.POST)
    public Result<List<ProvinceVo>> province() {
        Result<List<ProvinceVo>> result = new Result<>();
        result.success("").setData(loginApi.provinceList());
        return result;
    }

    @ApiOperation("展示市信息")
    @RequestMapping(value = "/city", method = RequestMethod.POST)
    public Result<List<CityVo>> city(@ApiParam("省份ID") @RequestBody LocationRequest locationRequest) {
        Result<List<CityVo>> result = new Result<>();
        result.success("").setData(loginApi.cityList(locationRequest.getProvinceId()));
        return result;
    }

    @ApiOperation("展示县区信息")
    @RequestMapping(value = "/district", method = RequestMethod.POST)
    public Result<List<DistrictVo>> district(@ApiParam("城市ID") @RequestBody LocationRequest locationRequest) {
        Result<List<DistrictVo>> result = new Result<>();
        result.success("").setData(loginApi.distinctList(locationRequest.getCityId()));
        return result;
    }

    @ApiOperation("展示街道信息")
    @RequestMapping(value = "/street", method = RequestMethod.POST)
    public Result<List<StreetVo>> street(@ApiParam("县区ID") @RequestBody LocationRequest locationRequest) {
        Result<List<StreetVo>> result = new Result<>();
        result.success("").setData(loginApi.streetList(locationRequest.getDistrictId()));
        return result;
    }
}
